home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Need help with a STRING that won't go away!!!
- Date: Mon, 01 Apr 96 16:48:38 GMT
- Organization: none
- Message-ID: <828377318snz@genesis.demon.co.uk>
- References: <4jh7e2$jjr@abel.cc.sunysb.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4jh7e2$jjr@abel.cc.sunysb.edu>
- ghauser@ic.sunysb.edu "George Hauser" writes:
-
- ...
-
- >#include <stdio.h>
- >#include <string.h>
- >#include <stdlib.h>
- >
- >#define linemax 194 /* The predifined lenght of the record */
- >
- >--- All previous functions and file openings are coded here.
- >
- > records = 0;
-
-
- > while(!feof(sourcefp))
- > {
- > if (ferror(sourcefp))
- > {
- > printf("\nError while reading source file.\n");
- > exit(1);
- > }
- > fgets(line,linemax,sourcefp); /* Get Bad Record */
-
- The system isn't prescient - feof() and ferror() test whether the last
- operation resulted in and end-of-file or error condition, not whether the
- next one will do. Most stdio functions have a return value that indicates
- EOF/error - it is best to use it. Replace the section above with:
-
- while(fgets(line,linemax,sourcefp) != NULL)
- {
-
- > rmgarbage(line); /* Remove bad chars */
- > fillrecords(line); /* Format the record line */
- >
- > /* here I tried checking for empty lines */
- > fputs(line,destfp); /* Write to disk */
- >
- > records++; /* Increment our counter */
- >
- > /* here I was setting the line[] to '\0' */
- >
- > }
-
- And if you wish you can add here:
-
- if (ferror(sourcefp))
- {
- printf("\nError while reading source file.\n");
- exit(1);
- }
-
- > fclose(sourcefp); /* Close source file. */
- > fclose(destfp); /* Close destination file. */
- > printf("Total Number Of Records Processed: %d \n", records);
- >} /* End */
- >
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-